home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 6: Level 6 / 17 Bit - Level 6 (1998)(Epic Marketing)[!].iso / quartz / q1082.dms / q1082.adf / src.lzh / Fig / copy.c < prev    next >
C/C++ Source or Header  |  1991-07-18  |  8KB  |  324 lines

  1. /* 
  2.  *    FIG : Facility for Interactive Generation of figures
  3.  *
  4.  *    Copyright (c) 1985 by Supoj Sutanthavibul (supoj@sally.UTEXAS.EDU)
  5.  *    January 1985.
  6.  *    1st revision : Aug 1985.
  7.  *
  8.  *    %W%    %G%
  9. */
  10. #include "fig.h"
  11. #include "resources.h"
  12. #include "alloc.h"
  13. #include "func.h"
  14. #include "object.h"
  15. #include "paintop.h"
  16.  
  17. #define            TOLERANCE    7
  18.  
  19. extern            (*canvas_kbd_proc)();
  20. extern            (*canvas_locmove_proc)();
  21. extern            (*canvas_leftbut_proc)();
  22. extern            (*canvas_middlebut_proc)();
  23. extern            (*canvas_rightbut_proc)();
  24. extern            (*return_proc)();
  25. extern            null_proc();
  26. extern            set_popupmenu();
  27. extern F_line        *line_search(), *copy_line();
  28. extern F_arc        *arc_search(), *copy_arc();
  29. extern F_ellipse    *ellipse_search(), *copy_ellipse();
  30. extern F_text        *text_search(), *copy_text();
  31. extern F_spline        *spline_search(), *copy_spline();
  32. extern F_compound    *compound_search(), *copy_compound();
  33.  
  34. extern F_compound    objects;
  35.  
  36. extern int        copy_selected();
  37.             init_copy();
  38.  
  39. copy_selected()
  40. {
  41.     canvas_kbd_proc = null_proc;
  42.     canvas_locmove_proc = null_proc;
  43.     canvas_leftbut_proc = init_copy;
  44.     canvas_middlebut_proc = null_proc;
  45.     canvas_rightbut_proc = set_popupmenu;
  46.     return_proc = copy_selected;
  47.     set_cursor(&pick15_cursor);
  48.     reset_action_on();
  49.     }
  50.  
  51. init_copy(x, y)
  52. int    x, y;
  53. {
  54.     F_line        *l, *line;
  55.     F_ellipse    *e, *ellipse;
  56.     F_text        *t, *text;
  57.     F_spline    *s, *spline;
  58.     F_arc        *a, *arc;
  59.     F_compound    *c, *compound;
  60.     int        px, py;
  61.  
  62.     if ((c = compound_search(x, y, TOLERANCE, &px, &py)) != NULL) {
  63.         compound = copy_compound(c);
  64.         erase_pointmarker();
  65.         set_temp_cursor(&null_cursor);
  66.         win_setmouseposition(canvas_swfd, px, py);
  67.         clean_up();
  68.         set_action_object(F_CREATE, O_COMPOUND);
  69.         insert_compound(&objects.compounds, compound);
  70.         set_latestcompound(compound);
  71.         init_compounddragging(compound, px, py);
  72.         }
  73.     else if ((l = line_search(x, y, TOLERANCE, &px, &py)) != NULL) {
  74.         line = copy_line(l);
  75.         erase_pointmarker();
  76.         set_temp_cursor(&null_cursor);
  77.         win_setmouseposition(canvas_swfd, px, py);
  78.         clean_up();
  79.         set_action_object(F_CREATE, O_POLYLINE);
  80.         insert_line(&objects.lines, line);
  81.         set_latestline(line);
  82.         init_linedragging(line, px, py);
  83.         }
  84.     else if ((t = text_search(x, y)) != NULL) {
  85.         text = copy_text(t);
  86.         erase_pointmarker();
  87.         set_temp_cursor(&null_cursor);
  88.         clean_up();
  89.         set_action_object(F_CREATE, O_TEXT);
  90.         insert_text(&objects.texts, text);
  91.         set_latesttext(text);
  92.         init_textdragging(text, x, y);
  93.         }
  94.     else if ((e = ellipse_search(x, y, TOLERANCE, &px, &py)) != NULL) {
  95.         ellipse = copy_ellipse(e);
  96.         erase_pointmarker();
  97.         set_temp_cursor(&null_cursor);
  98.         win_setmouseposition(canvas_swfd, px, py);
  99.         clean_up();
  100.         set_action_object(F_CREATE, O_ELLIPSE);
  101.         insert_ellipse(&objects.ellipses, ellipse);
  102.         set_latestellipse(ellipse);
  103.         init_ellipsedragging(ellipse, px, py);
  104.         }
  105.     else if ((a = arc_search(x, y, TOLERANCE, &px, &py)) != NULL) {
  106.         arc = copy_arc(a);
  107.         erase_pointmarker();
  108.         set_temp_cursor(&null_cursor);
  109.         win_setmouseposition(canvas_swfd, px, py);
  110.         clean_up();
  111.         set_action_object(F_CREATE, O_ARC);
  112.         insert_arc(&objects.arcs, arc);
  113.         set_latestarc(arc);
  114.         init_arcdragging(arc, px, py);
  115.         }
  116.     else if ((s = spline_search(x, y, TOLERANCE, &px, &py)) != NULL) {
  117.         spline = copy_spline(s);
  118.         erase_pointmarker();
  119.         set_temp_cursor(&null_cursor);
  120.         win_setmouseposition(canvas_swfd, px, py);
  121.         clean_up();
  122.         set_action_object(F_CREATE, O_SPLINE);
  123.         insert_spline(&objects.splines, spline);
  124.         set_latestspline(spline);
  125.         init_splinedragging(spline, px, py);
  126.         }
  127.     else
  128.         return;
  129.     canvas_leftbut_proc = canvas_rightbut_proc = null_proc;
  130.     }
  131.  
  132. F_arc *
  133. copy_arc(a)
  134. F_arc    *a;
  135. {
  136.     F_arc    *arc;
  137.  
  138.     if (NULL == (Arc_malloc(arc))) {
  139.         put_msg(Err_mem);
  140.         return(NULL);
  141.         }
  142.     *arc = *a;
  143.     arc->next = NULL;
  144.     return(arc);
  145.     }
  146.  
  147. F_ellipse *
  148. copy_ellipse(e)
  149. F_ellipse    *e;
  150. {
  151.     F_ellipse    *ellipse;
  152.  
  153.     if (NULL == (Ellipse_malloc(ellipse))) {
  154.         put_msg(Err_mem);
  155.         return(NULL);
  156.         }
  157.     *ellipse = *e;
  158.     ellipse->next = NULL;
  159.     return(ellipse);
  160.     }
  161.  
  162. F_line *
  163. copy_line(l)
  164. F_line    *l;
  165. {
  166.     F_line    *line;
  167.     F_point    *p, *point, *last_point;
  168.  
  169.     if (NULL == (Line_malloc(line))) {
  170.         put_msg(Err_mem);
  171.         return(NULL);
  172.         }
  173.     *line = *l;
  174.     line->points = Point_malloc(point);
  175.     last_point = point;
  176.     p = l->points;
  177.     *point = *p;
  178.     point->next = NULL;
  179.     for (p = p->next; p != NULL; p = p->next) {
  180.         last_point->next = Point_malloc(point);
  181.         if (point == NULL) return(NULL);
  182.         *point = *p;
  183.         point->next = NULL;
  184.         last_point = point;
  185.         }
  186.     line->next = NULL;
  187.     return(line);
  188.     }
  189.  
  190. F_spline *
  191. copy_spline(s)
  192. F_spline    *s;
  193. {
  194.     F_spline    *spline;
  195.     F_point        *p, *point, *last_point;
  196.     F_control    *cntrl_pnt, *cp, *last_cntrl_pnt;
  197.  
  198.     if (NULL == (Spline_malloc(spline))) {
  199.         put_msg(Err_mem);
  200.         return(NULL);
  201.         }
  202.     *spline = *s;
  203.     spline->next = NULL;
  204.  
  205.     Point_malloc(point);
  206.     last_point = spline->points = point;
  207.     p = s->points;
  208.     *point = *p;
  209.     for (p = p->next; p != NULL; p = p->next) {
  210.         last_point->next = Point_malloc(point);
  211.         if (point == NULL) return(NULL);
  212.         *point = *p;
  213.         last_point = point;
  214.         }
  215.     last_point->next = NULL;
  216.  
  217.     spline->controls = NULL;
  218.     if (s->controls == NULL) return(spline);
  219.  
  220.     last_cntrl_pnt = spline->controls = Control_malloc(cntrl_pnt);
  221.     cp = s->controls;
  222.     *cntrl_pnt = *cp;
  223.     for (cp = cp->next; cp != NULL; cp = cp->next) {
  224.         last_cntrl_pnt->next = Control_malloc(cntrl_pnt);
  225.         if (cntrl_pnt == NULL) return(NULL);
  226.         *cntrl_pnt = *cp;
  227.         last_cntrl_pnt = cntrl_pnt;
  228.         }
  229.     last_cntrl_pnt->next = NULL;
  230.  
  231.     return(spline);
  232.     }
  233.  
  234. F_text *
  235. copy_text(t)
  236. F_text    *t;
  237. {
  238.     F_text        *text;
  239.  
  240.     if (NULL == (Text_malloc(text))) {
  241.         put_msg(Err_mem);
  242.         return(NULL);
  243.         }
  244.     *text = *t;
  245.     text->cstring = malloc((unsigned)(strlen(t->cstring)+1));
  246.     if (text->cstring == NULL) {
  247.         free((char*)text);
  248.         put_msg(Err_mem);
  249.         return(NULL);
  250.         }
  251.     strcpy(text->cstring, t->cstring);
  252.     text->next = NULL;
  253.     return(text);
  254.     }
  255.  
  256. F_compound *
  257. copy_compound(c)
  258. F_compound    *c;
  259. {
  260.     F_ellipse    *e, *ee;
  261.     F_arc        *a, *aa;
  262.     F_line        *l, *ll;
  263.     F_spline    *s, *ss;
  264.     F_text        *t, *tt;
  265.     F_compound    *cc, *ccc, *compound;
  266.  
  267.     if (NULL == (Compound_malloc(compound))) {
  268.         put_msg(Err_mem);
  269.         return(NULL);
  270.         }
  271.     compound->nwcorner = c->nwcorner;
  272.     compound->secorner = c->secorner;
  273.     compound->arcs = NULL;
  274.     compound->ellipses = NULL;
  275.     compound->lines = NULL;
  276.     compound->splines = NULL;
  277.     compound->texts = NULL;
  278.     compound->compounds = NULL;
  279.     compound->next = NULL;
  280.     for (e = c->ellipses; e != NULL; e = e->next) {
  281.         if (NULL == (ee = copy_ellipse(e))) {
  282.         put_msg(Err_mem);
  283.         return(NULL);
  284.         }
  285.         insert_ellipse(&compound->ellipses, ee);
  286.         }
  287.     for (a = c->arcs; a != NULL; a = a->next) {
  288.         if (NULL == (aa = copy_arc(a))) {
  289.         put_msg(Err_mem);
  290.         return(NULL);
  291.         }
  292.         insert_arc(&compound->arcs, aa);
  293.         }
  294.     for (l = c->lines; l != NULL; l = l->next) {
  295.         if (NULL == (ll = copy_line(l))) {
  296.         put_msg(Err_mem);
  297.         return(NULL);
  298.         }
  299.         insert_line(&compound->lines, ll);
  300.         }
  301.     for (s = c->splines; s != NULL; s = s->next) {
  302.         if (NULL == (ss = copy_spline(s))) {
  303.         put_msg(Err_mem);
  304.         return(NULL);
  305.         }
  306.         insert_spline(&compound->splines, ss);
  307.         }
  308.     for (t = c->texts; t != NULL; t = t->next) {
  309.         if (NULL == (tt = copy_text(t))) {
  310.         put_msg(Err_mem);
  311.         return(NULL);
  312.         }
  313.         insert_text(&compound->texts, tt);
  314.         }
  315.     for (cc = c->compounds; cc != NULL; cc = cc->next) {
  316.         if (NULL == (ccc = copy_compound(cc))) {
  317.         put_msg(Err_mem);
  318.         return(NULL);
  319.         }
  320.         insert_compound(&compound->compounds, ccc);
  321.         }
  322.     return(compound);
  323.     }
  324.